import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

import Layout from '../layout'

/**
 * Note: Layout 组件移植自 vue-element-admin 项目，可以通过下面的 routes 配置自动生成侧边栏和面包屑导航
 *       之所以要移植而不是使用 vue-element-admin 项目是因为该项目过于庞大，即使是 vue-admin-template 项目也有过多的依赖
 *       移植过程中主要工作为：
 *          1. 减少依赖，尤其是去除了对 vuex 的依赖，本项目仅为中小型单页应用，根据 vuex 官方的建议，没必要使用 vuex 插件，
 *             对 Layout 中需要使用状态管理的部分，我手动写了一个简单的状态管理，参考资料见
 *             https://cn.vuejs.org/v2/guide/state-management.html#%E7%AE%80%E5%8D%95%E7%8A%B6%E6%80%81%E7%AE%A1%E7%90%86%E8%B5%B7%E6%AD%A5%E4%BD%BF%E7%94%A8
 *             https://cn.vuejs.org/v2/guide/components-edge-cases.html#%E4%BE%9D%E8%B5%96%E6%B3%A8%E5%85%A5
 *             https://segmentfault.com/a/1190000020954324
 *          2. 剔除了部分不需要的功能，如侧边栏对svg图标的支持，面包屑导航对通配符路径解析的支持等
 *          3. 修复了部分bug，如侧边栏图标在收起后位置略微偏左，影响美观的问题
 *          4. 部分修改项目的组织方式，将SCSS样式表编译为CSS，并内置于模块内
 *
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'el-icon-x'            the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

const routes = [
    {
        path: '/',
        component: Layout,
        children: [{
            path: '/',
            name: 'Home',
            component: () => import('@/views/Home.vue'),
            meta: {title: 'Home', icon: 'el-icon-s-home'}
        }]
    },
    {
        path: '/about',
        component: Layout,
        children: [
            {
                path: '/about',
                name: 'About',
                component: () => import('@/views/About.vue'),
                meta: {title: 'About', icon: 'el-icon-menu'}
            }
        ]
    }
]

const router = new VueRouter({
    routes
})

export default router
